package RestWS;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import model.Customer;

import convert.*;
import dao.CustomerDao;

@Path("/customer")
public class CustomersResource {
	
	@GET
	@Path("/info1")
	@Produces(MediaType.APPLICATION_JSON)
	public List<CustomerBN>  getCustomerList()
	{
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList=customerBNsHelp();
		  		
		return customerBnList;
	}
	

	
	
	@GET
	@Path("/info2")
	@Produces(MediaType.APPLICATION_XML)
	public List<CustomerBN>  getCustomerListall()
	{
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList=customerBNsHelp();
		  		
		return customerBnList;
	}
	
	
	@GET
	@Path("/info3")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public List<CustomerBN>  getCustomerListxml()
	{
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList=customerBNsHelp();
		  		
		return customerBnList;
	}
	
	
	public List<CustomerBN> customerBNsHelp()
	{
		
		
		  List<CustomerBN> bns=new ArrayList<CustomerBN>();
		
				CustomerDao customerDao=new CustomerDao();
				
				List<Customer> customers=customerDao.getCustomerList();
				
			    Iterator<Customer> iterator=customers.iterator();
				
			    while (iterator.hasNext()) {
					Customer customer = (Customer) iterator.next();
					
					CustomerBN customerBN=new CustomerBN();
					customerBN.setAddress(customer.getAddres());
					customerBN.setName(customer.getName());
					customerBN.setId(customer.getId());
					bns.add(customerBN);
					
				}

		
		return bns;
	}
	
	

}
